/////////////////////////////////////////////
/// Who is member of *
/////////////////////////////////////////////
// fetching the log
log = context.getLog()



// query for member names
memberQuery = "SELECT DISTINCT ?name FROM <http://xmlns.com/foaf/spec/index.rdf> WHERE {"+
	"?s ?p1 ?subjectpattern. ?s <http://xmlns.com/foaf/0.1/member> ?person. ?person <http://xmlns.com/foaf/0.1/name> ?name."+
	"FILTER regex(?subjectpattern, '.*"+context.getWildcard(1)+".*', 'i').}"
log.info(memberQuery)
//context.sendMessageToUser(documentQuery)

counter = 0;
members = context.queryForTable(memberQuery,true,null,null)
members.each(){res->
	if(res.errors==null||res.errors.empty){
		
		counter = counter + res.getResultCount()
		if (res.getResultCount() > 0) context.sendMessageToUser("From " + res.getStoreName() + ":")
		res.getResultRows().each(){ 
			log.info(it["name"])
			context.sendMessageToUser(" * "+it["name"])
		}
	}else{
		context.sendMessageToUser("Some error occured: " + res.errors);
	}
}
if(counter == 0) context.sendMessageToUser("Sorry, I can't answer your question.")

